/*
	Copyright (C) 2013 Pontificia Universidad Catolica del Peru
	contact: http://avatar.inf.pucp.edu.pe/realidad-aumentada/
	address contact: Av. Universitaria 1801, San Miguel, Lima-Peru.
	
	This file is part of UbicAR PUCP.

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with This program.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Author: Pedro Carrión Castagnola
	Pontificia Universidad Catolica del Peru
	Direccion de Informatica Academica
	
	Modified by: Alvaro Roger Agüero Sánchez, Rodolfo Javier Galvez Meza
	Pontificia Universidad Catolica del Peru
	Departamento de Ingeniería
*/

package org.grupoavatar.guiaubicua.entidades;

import java.util.Comparator;

import org.grupoavatar.guiaubicua.mix.DataView;
import org.grupoavatar.guiaubicua.mix.Marker;

public class MarkerComparator implements Comparator<Marker> {

	public static final int ORDENAMIENTO_CATEGORIA = 0;
	public static final int ORDENAMIENTO_ALFABETICO = 1;
	public static final int ORDENAMIENTO_DISTANCIA = 2;
	public static final int ORDENAMIENTO_RELEVANCIA = 3;
	
	public static int ultipoOrdenamientoSeleccionado = ORDENAMIENTO_ALFABETICO;
	
	private int ordenamiento;

	public MarkerComparator(int ordenamiento)	{
		this.ordenamiento = ordenamiento;
		ultipoOrdenamientoSeleccionado = ordenamiento;
	}
	
	@Override
	public int compare(Marker o1, Marker o2) {
		switch(ordenamiento) {
			case ORDENAMIENTO_ALFABETICO:
			case ORDENAMIENTO_CATEGORIA:	
				String titulo1 = DataView.convertir(o1.getTitle());
				String titulo2 = DataView.convertir(o2.getTitle());
				int comparacionTitulos = titulo1.compareToIgnoreCase(titulo2);
				if (ordenamiento == ORDENAMIENTO_ALFABETICO)	{
					return comparacionTitulos;
				} else {
					int comparacionCategorias = o1.getPOI().getCategoria().compareTo(o2.getPOI().getCategoria());
					if (comparacionCategorias == 0)	{
						return comparacionTitulos;
					}
					return comparacionCategorias;
				}
			case ORDENAMIENTO_RELEVANCIA:
				return 0;
			default:
				return (int)(o1.getDistance()) - (int)(o2.getDistance());
		}
	}
}